#ifndef __BUFFER_HPP__
#define __BUFFER_HPP__

namespace purewell
{

//! \brief Buffer.
class PWBuffer
{
public:
	//! \brief Create buffer.
	//! \param[in] type Buffer type.
	//! \return On success, buffer pointer or NULL.
	static PWBuffer* create(int type);

	//! \brief Release buffer.
	//! \param[in] obj Buffer object to release.
	static void release(PWBuffer* obj);

public:
	//! \brief Read data from buffer. No pop.
	//! \param[out] buf Buffer.
	//! \param[in] blen Buffer length.
	//! \return On success, operated length or -1.
	virtual ssize_t read(void* buf, size_t blen) const = 0;

	//! \brief Read data from buffer. Pop.
	//! \param[out] buf Buffer.
	//! \param[in] blen Buffer length.
	//! \return On success, operated length or -1.
	virtual ssize_t readAndSkip(void* buf, size_t blen) = 0;

	//! \brief Skip data from buffer. Pop.
	//! \param[in] blen Buffer length.
	//! \return On success, operated length or -1.
	virtual ssize_t skip(size_t blen) = 0;

	//! \brief Write data to buffer.
	//! \param[out] buf Buffer.
	//! \param[in] blen Buffer length.
	//! \return On success, operated length or -1.
	virtual ssize_t write(const void* buf, size_t blen) = 0;

public:	
	//! \brief Get capacity.
	//! \return Capacity size.
	virtual size_t getCapacity(void) const = 0;

	//! \brief Get current size.
	//! \return Current size.
	virtual size_t getCurrentSize(void) const = 0;

	//! \brief Get type.
	//! \return Type.
	virtual int getType(void) const = 0;

	//! \brief Get auto-increasement size.
	//! \return Auto-increasement size.
	virtual bool getAutoSize(void) const = 0;

	//! \brief Clear buffer.
	virtual void clear(void) = 0;

	//! \brief Check buffer is empty.
	//! \return On empty, true.
	virtual bool isEmpty(void) const = 0;

	//! \brief Read line from buffer. No pop.
	//! \param[out] buf Buffer.
	//! \param[in] blen Buffer length.
	//! \return On success, operated size or -1.
	virtual ssize_t readLine(void* buf, size_t blen) const = 0;

	//! \brief Read line from buffer. Pop.
	//! \param[out] buf Buffer.
	//! \param[in] blen Buffer length.
	//! \return On success, operated size or -1.
	virtual ssize_t readLineAndSkip(void* buf, size_t blen) = 0;

public:
	//! \brief Stream operator.
	//! \param[in] str C-style string to write on buffer.
	//! \return Reference of this object.
	virtual PWBuffer& operator << (const char* str);

private:	
	//! \brief Assign operator.
	//! \param[in] obj Object.
	//! \return Reference of this object.
	inline PWBuffer& operator = (const PWBuffer& obj) { return *this; };

protected:
	explicit PWBuffer();
	virtual ~PWBuffer();
};

};//namespace purewell

#endif//!__BUFFER_HPP__

